home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWLocaleSnapshot.z / RWLocaleSnapshot
Encoding:
Text File  |  2002-10-03  |  9.0 KB  |  199 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((3333CCCC++++++++))))                                  RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWLocaleSnapshot - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <locale.h>
  13.  
  14.  
  15.  
  16.               #include <rw/locale.h>
  17.           RWLocaleSnapshot ourLocale("");  // encapsulate user's formats
  18.  
  19.  
  20.  
  21.  
  22. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  23.      The class RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt implements the RRRRWWWWLLLLooooccccaaaalllleeee interface using
  24.      Standard C library facilities.  To use it, the program creates an
  25.      RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt instance.  The constructor of the instance queries the
  26.      program's environment (using standard C library functions such as
  27.      llllooooccccaaaalllleeeeccccoooonnnnvvvv(((()))), ssssttttrrrrffffttttiiiimmmmeeee(((()))), and, if available , vendor specific library
  28.      functions) to learn everything it can about formatting conventions in
  29.      effect at the moment of instantiation.  When done, the locale can then be
  30.      switched and another instance of RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt created.  By creating
  31.      multiple instances of RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt, your program can have more than
  32.      one locale active at the same time, something that is difficult to do
  33.      with the Standard C library facilities.  NNNNooootttteeee:  RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt does not
  34.      encapsulate character set, collation, or message information.  Class
  35.      RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt has a set of public data members initialized by its
  36.      constructor with information extracted from its execution environment.
  37.  
  38. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  39.      None
  40.  
  41. EEEExxxxaaaammmmpppplllleeee
  42.      Try this program with the environmental variable LLLLAAAANNNNGGGG set to various
  43.      locales:
  44.  
  45.               #include <rw/rwdate.h>
  46.  
  47.  
  48.  
  49.               #include <rw/locale.h>
  50.           #include <iostream.h>
  51.  
  52.  
  53.               main(){
  54.  
  55.  
  56.  
  57.                RWLocaleSnapshot *userLocale = new RWLocaleSnapshot("");
  58.            RWLocale::global(userLocale);
  59.            // Print a number using the global locale:
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((3333CCCC++++++++))))                                  RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.            cout << RWLocale::global().asString(1234567.6543) << endl;
  75.            // Now get and print a date:
  76.            cout << "enter a date: " << flush;
  77.            RWDate date;
  78.            cin >> date;
  79.            if (date.isValid())
  80.            cout << date << endl;
  81.            else
  82.            cout << "bad date" << endl;
  83.            delete userLocale;
  84.            return 0;
  85.           }
  86.  
  87. EEEEnnnnuuuummmmeeeerrrraaaattttiiiioooonnnnssss
  88.               enum
  89.           RRRRWWWWDDDDaaaatttteeeeOOOOrrrrddddeeeerrrr { DMY, MDY, YDM, YMD };
  90.  
  91.  
  92.  
  93. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  94.               RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt(const char* localeName = 0);
  95.  
  96.  
  97.      Constructs an RRRRWWWWLLLLooooccccaaaalllleeee object by extracting formats from the global
  98.      locale environment.  It uses the Standard C Library function sssseeeettttllllooooccccaaaalllleeee(((())))
  99.      to set the named locale, and then restores the previous global locale
  100.      after formats have been extracted.  If llllooooccccaaaalllleeeeNNNNaaaammmmeeee is 0, it simply uses
  101.      the current locale.  The most useful locale name is the empty string, "",
  102.      which is a synonym for the user's chosen locale (usually specified by the
  103.      environment variable LLLLAAAANNNNGGGG).
  104.  
  105. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  106.               virtual RWCString
  107.           aaaassssSSSSttttrrrriiiinnnngggg(long) const;
  108.           virtual RWCString
  109.           aaaassssSSSSttttrrrriiiinnnngggg(unsigned long) const;
  110.           virtual RWCString
  111.           aaaassssSSSSttttrrrriiiinnnngggg(double f, int precision = 6,
  112.           RWBoolean showpoint = 0) const;
  113.           virtual RWCString
  114.           aaaassssSSSSttttrrrriiiinnnngggg(struct tm* tmbuf,char format, const RWZone& zone);
  115.                    const;
  116.           virtual RWCString
  117.           aaaassssSSSSttttrrrriiiinnnngggg(struct tm* tmbuf,char* format,
  118.                    const RWZone& zone) const;
  119.           virtual RWCString
  120.           mmmmoooonnnneeeeyyyyAAAAssssSSSSttttrrrriiiinnnngggg(double value,enum CurrSymbol = LOCAL) const;
  121.           virtual RWBoolean
  122.           ssssttttrrrriiiinnnnggggTTTTooooNNNNuuuummmm  (const RWCString&, double* fp) const;
  123.           virtual RWBoolean
  124.           ssssttttrrrriiiinnnnggggTTTTooooNNNNuuuummmm  (const RWCString&, long* ip  ) const;
  125.           virtual RWBoolean
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((3333CCCC++++++++))))                                  RRRRWWWWLLLLooooccccaaaalllleeeeSSSSnnnnaaaappppsssshhhhooootttt((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.           ssssttttrrrriiiinnnnggggTTTTooooDDDDaaaatttteeee (const RWCString&, struct tm*) const;
  141.           virtual RWBoolean
  142.           ssssttttrrrriiiinnnnggggTTTTooooTTTTiiiimmmmeeee (const RWCString&, struct tm*) const;
  143.           virtual RWBoolean
  144.           ssssttttrrrriiiinnnnggggTTTTooooMMMMoooonnnneeeeyyyy(const RWCString&, double*   ,
  145.                         RWLocale::CurrSymbol=LOCAL) const;
  146.  
  147.  
  148.      Redefined from class RRRRWWWWLLLLooooccccaaaalllleeee.  These virtual functions follow the
  149.      interface described under class RRRRWWWWLLLLooooccccaaaalllleeee.  They generally work by
  150.      converting values to and from strings using the rules specified by the
  151.      ssssttttrrrruuuucccctttt llllccccoooonnnnvvvv values (see <<<<llllooooccccaaaalllleeee....hhhh>>>>) encapsulated in self.
  152.  
  153. PPPPuuuubbbblllliiiicccc DDDDaaaattttaaaa MMMMeeeemmmmbbbbeeeerrrrssss
  154.               RWCString     decimal_point_;
  155.           RWCString     thousands_sep_;
  156.           RWCString     grouping_;
  157.           RWCString     int_curr_symbol_;
  158.           RWCString     currency_symbol_;
  159.           RWCString     mon_decimal_point_;
  160.           RWCString     mon_thousands_sep_;
  161.           RWCString     mon_grouping_;
  162.           RWCString     positive_sign_;
  163.           RWCString     negative_sign_;
  164.           char          int_frac_digits_;
  165.           char          frac_digits_;
  166.           char          p_cs_precedes_;
  167.           char          p_sep_by_space_;
  168.           char          n_cs_precedes_;
  169.           char          n_sep_by_space_;
  170.           char          p_sign_posn_;
  171.           char          n_sign_posn_;
  172.  
  173.  
  174.      These are defined identically as the correspondingly-named members of the
  175.      standard C library type llllccccoooonnnnvvvv, from <<<<llllooooccccaaaalllleeee....hhhh>>>>.
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.